package com.itheima.d2_byte_stream;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;

/*
     目标：使用字节流完成对文件的复制操作。
     数据源
     目的地
 */
public class CopyTest5 {
    public static void main(String[] args) throws Exception {
//        long start = System.currentTimeMillis();
//        copy1();
//        long end = System.currentTimeMillis();
//        System.out.println(end - start);

        long start2 = System.currentTimeMillis();
        copy2();
        long end2 = System.currentTimeMillis();
        System.out.println(end2 - start2);
    }

    private static void copy1() throws Exception {
        FileInputStream fis = new FileInputStream("D:\\学习\\毕业设计\\备份\\初稿_王鹏飞_毕业设计1-7.pdf");
        FileOutputStream fos = new FileOutputStream("哈哈.pdf");

        int byt;
        while((byt = fis.read()) != -1){
            fos.write(byt);
        }
    }

    private static void copy2() throws Exception {
        FileInputStream fis = new FileInputStream("D:\\学习\\毕业设计\\备份\\初稿_王鹏飞_毕业设计1-7.pdf");
        FileOutputStream fos = new FileOutputStream("哈哈.pdf");

        int len;
        byte[] bytes = new byte[4096];

        while((len = fis.read(bytes)) != -1){
            fos.write(bytes,0,len);
        }
    }
}
